package com.tianya.controller;

import com.tianya.common.Results;
import com.tianya.domain.dto.HomeVisitRequestDTO;
import com.tianya.domain.entity.Homevisit;
import com.tianya.domain.vo.PageResultVO;
import com.tianya.service.HomevisitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author TianYaGuoKe
 * @date 2025/5/26 13:43
 * @description HomeVisitController
 */
@Api("家访访问管理")
@RestController
@RequestMapping("/homeVisit")
public class HomeVisitController {

    @Resource
    private HomevisitService homevisitService;


    @ApiOperation("创建家访访问")
    @PostMapping
    public Results createHomeVisit(@RequestBody HomeVisitRequestDTO homeVisitRequestDTO) {
        homevisitService.createHomeVisit(homeVisitRequestDTO);
        return Results.success();
    }

    @ApiOperation("分页获取家访访问")
    @PostMapping("/page")
    public Results<PageResultVO<Homevisit>> pageHomeVisit(@RequestParam(defaultValue = "1") Integer pageNum,
                                                          @RequestParam(defaultValue = "10") Integer pageSize,
                                                          @RequestBody HomeVisitRequestDTO homeVisitRequestDTO) {
        return Results.success(homevisitService.pageHomeVisit(pageNum, pageSize, homeVisitRequestDTO));
    }

    @ApiOperation("获取家访访问")
    @GetMapping
    public Results<Homevisit> getHomeVisit(@RequestParam Long id) {
        return Results.success(homevisitService.getById(id));
    }

    @ApiOperation("更新家访访问")
    @PutMapping
    public Results updateHomeVisit(@RequestBody Homevisit homevisit) {
        homevisitService.updateById(homevisit);
        return Results.success();
    }

    @ApiOperation("删除家访访问")
    @DeleteMapping("/{id}")
    public Results deleteHomeVisit(@PathVariable Long id) {
        homevisitService.removeById(id);
        return Results.success();
    }
}
